//
//  YSAccountCenterCtrl.m
//  Yueshi
//
//  Created by Northwan on 15/7/30.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//  结算中心

#import "YSAccountCenterCtrl.h"
#import "YSAccountCenterRes.h"
#import "YSClubDataTool.h"
#import "YSAccountCenterCell.h"
#import "YSAccountCenterBusinessHeaderView.h"
#import "YSAccountCenterItemFrame.h"
#import "YSAccountCenterBottomBar.h"
#import "YSAccountCenterHeaderView.h"
#import "YSAccountCenterEmptyHeaderView.h"
#import "YSAddressCtrl.h"
#import "YSAccountCenterContainerFooterView.h"
#import "WXPayClient.h"
#import "AlipayUtil.h"
#import "YSAccountCenterBusinessFooterView.h"
#import "YSUserMarkModel.h"
#import "YSAccountCenterExperienceBusinessFooterView.h"
#import "YSNewAddressCtrl.h"
#import "YSVoucher.h"
#import "YSVoucherCtrl.h"
//#import "UPAPayPlugin.h"
//#import <PassKit/PassKit.h>

@interface YSAccountCenterCtrl ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIAlertViewDelegate>
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *allFrames;
@property (assign, nonatomic) CGFloat allCellHeight;
@property (strong, nonatomic) YSAccountCenterRes *result;
@property (strong, nonatomic) YSAccountCenterBottomBar *bottomBar;
@property (strong, nonatomic) YSAccountCenterHeaderView *headerView;
@property (strong, nonatomic) YSAccountCenterEmptyHeaderView *emptyHeaderView;
@property (strong, nonatomic) YSAccountCenterContainerFooterView *footerView;

@property (strong, nonatomic) YSAddOrderRes *addOrderResult;
@property (copy, nonatomic) NSString *selectProdIds;
@property (copy, nonatomic) NSString *orderCode;

@property(nonatomic, assign) AccountCenterFinishType targetType;
@property(nonatomic, assign) AccountCenterProductType productType;

@property (nonatomic, weak) UIView *currentEditView;
@property (nonatomic, assign) CGFloat moveDis;//移动距离
@property (nonatomic, assign) CGFloat keyboardHeight;//键盘高度，如果为0，代表当前不是编辑模式

@property (nonatomic, strong) YSVoucher *voucher;

//定义完成按钮
@property (weak,nonatomic) UIButton *doneInKeyboardButton;
@end

@implementation YSAccountCenterCtrl


-(instancetype)initWithOrdreCode:(NSString *)orderCode selectProdIds:(NSString *)selectProdIds targetType:(AccountCenterFinishType)targetType productType:(AccountCenterProductType)productType{
    self = [super init];
    if(self){
        self.selectProdIds = selectProdIds;
        self.orderCode = orderCode;
        self.targetType = targetType;
        self.productType = productType;
    }
    return self;
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //添加键盘弹出与隐藏的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

/*
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
      [self.view endEditing:YES];
}*/

- (void)textFieldBeginEditing:(UITextField *)textField{
    NSLog(@"textViewShouldBeginEditing");
    self.currentEditView = textField;
    if (self.keyboardHeight!=0) {
        [self adjustLocationWithKeyboardHeight:self.keyboardHeight];
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@"textFieldDidEndEditing");
    NSLog(@"section：%ld",textField.tag);
    YSSupplier *supplier =  _result.supplierList[textField.tag];
    NSLog(@"text:%@",textField.text);
    [supplier setUserRemark:textField.text];
}

- (void)keyboardWillShow:(NSNotification *)notif
{
    //在键盘显示的时候去调整view
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    
    self.keyboardHeight = keyboardSize.height;
    [self adjustLocationWithKeyboardHeight:keyboardSize.height];
}

-(void)adjustLocationWithKeyboardHeight:(CGFloat)keyboardHeight{
    //在键盘弹出时也要让tableView能够全屏滚动
    [self.tableView setHeight:SCREENH-NavWithStatusBarH-keyboardHeight];
    
    UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
    CGRect editViewRect = [self.currentEditView convertRect:self.currentEditView.bounds toView:window];
    
    //首页判断键盘有没有遮挡view，如果没有遮挡，那个什么也不做
    CGFloat viewMaxY = CGRectGetMaxY(editViewRect);
    if (viewMaxY+10>SCREENH-keyboardHeight) {
        //代表键盘遮挡了view
        //需要调整uiscrollview的contentoffset移动
        self.moveDis = (viewMaxY+10)-(SCREENH-keyboardHeight);
        [UIView animateWithDuration:0.25 animations:^{
            [self.tableView setContentOffset:CGPointMake(0, self.tableView.contentOffset.y+self.moveDis)];
        }];
    }
}

-(void)keyboardWillHide:(NSNotification*)notif{
    //键盘隐藏时候恢复tableView原本的高度
    [self.tableView setHeight:SCREENH-NavWithStatusBarH-YSAccountCenterBottomBarHeight];
    
    self.keyboardHeight = 0;
    self.currentEditView = nil;
    if (self.tableView.contentOffset.y!=0) {
        [self.tableView setContentOffset:CGPointMake(0, self.tableView.contentOffset.y-self.moveDis)];
    }
    self.moveDis = 0;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem setTitle:@"结算中心"];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tapHead:) name:kTapAccountCenterAddressHeadNortif object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(chooseAddress:) name:kChooseAddressFinishNortif object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(payStatus:) name:kPayResultStatusNortif object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selectVoucherFinish:) name:kChooseVoucherFinishNortif object:nil];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];
    
    [self initHeaderViewWithFooterView];
    [self initTableView];
    [self initBottomBar];
    
    _allFrames = [NSMutableArray array];
    [self requestData];
}

-(void)tapAction:(UIGestureRecognizer *)sender{
    [self.view endEditing:YES];
}

-(void)initHeaderViewWithFooterView{
    self.footerView = [[YSAccountCenterContainerFooterView alloc]initWithType:self.productType];
    if(self.productType == ordinaryProductType){
        self.headerView = [YSAccountCenterHeaderView headerView];
        self.emptyHeaderView = [YSAccountCenterEmptyHeaderView emptyHeaderView];
    }
   [self.footerView.payView.voucherCover addTarget:self action:@selector(selectVoucher:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)initBottomBar{
    __weak YSAccountCenterCtrl *ctrl = self;
    _bottomBar = [YSAccountCenterBottomBar bottomBar];
    [_bottomBar setX:0];
    [_bottomBar setWidth:SCREENW];
    [_bottomBar setY:SCREENH - YSAccountCenterBottomBarHeight - NavWithStatusBarH];
    [_bottomBar setHidden:YES];
    [self.view addSubview:_bottomBar];
    [_bottomBar setOperation:^{
        //commit callback
        [ctrl addOrder];
    }];
}

-(void)addOrder{
    if(self.footerView.payView.currentPayMode == wxPayMode && ![WXApi isWXAppInstalled]){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提交失败" message:@"安装微信才可使用微信支付\n建议尝试支付宝支付" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        return;
    }
   
    NSMutableArray *marks = [NSMutableArray array];
    
    for (YSSupplier *sp in _result.supplierList) {
        if(!ISBLANK(sp.userRemark)){
            YSUserMarkModel *remark = [YSUserMarkModel new];
            [remark setSupplierId:sp.supplierId];
            [remark setRemark: sp.userRemark];
            [marks addObject:[remark JSONObject]];
            NSLog(@"商户id:%ld,留言内容:%@",sp.supplierId,sp.userRemark);
        }
    }
    
    NSString* userMarks = nil;
    
    if(marks.count){
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:[marks keyValues]forKey:@"userRemark"];
        userMarks = [dic JSONString];
        NSLog(@"%@",userMarks);
    }
    
    if(self.productType == experienceProductType){
       NSString *phone =  self.footerView.phoneView.phoneTF.text;
        if(ISBLANK(phone)){
            ShowTips(@"请输入手机号");
            return;
        }else{
            if(!phone.isValidatePhone){
                ShowTips(@"非法手机号");
                return;
            }
            self.result.volumePhone = phone;
        }
    }
    
    [TalkingData trackEvent:kEventOrderCommit];
    
    [YSClubDataTool addOrderWithAddressId:self.result.addressInfo.addressId payMode:self.footerView.payView.currentPayMode orderCode:self.orderCode userRemark:userMarks volumePhone:self.result.volumePhone voucherId:_voucher == nil?0:_voucher.voucherId  success:^(YSAddOrderRes *result) {
        if(result.isSucc){
            [self dealPayMode:result];
        }else{
            if(result.code == 1001 || result.code == 1002){
                [Utils clearExitInfo];
                [Utils showLoginCtrl:self];
            }
            ShowEnterTips(result.data);
        }
    } failure:^(NSError *error) {
        ShowTips(kRequestFailure);
    }];
}

-(void)dealPayMode:(YSAddOrderRes *)result{
    _addOrderResult = result;
    if(self.footerView.payView.currentPayMode == alipayMode){
     [[[AlipayUtil alloc]init] callPay:result.orderNum prodName:result.prodName prodDetail:result.prodDetail money:result.money notify_url:result.notifyUrl showProdUrl:result.showProdUrl];
    }else if(self.footerView.payView.currentPayMode == wxPayMode){
        if([WXApi isWXAppInstalled]){
            [[[WXPayClient alloc]init] pay:result.orderNum prodName:result.prodName money:result.money notifyUrl:result.notifyUrl container:self.view];
        }
//    }else{
//        if ([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkChinaUnionPay]]) {
//            [UPAPayPlugin startPay:result.tn mode:@"01" viewController:self delegate:self andAPMechantID:kAppleMerchantID];
//        }
    }
}

#pragma mark 响应apple pay返回的支付结果
//- (void)UPAPayPluginResult:(UPPayResult *)payResult{
//    NSString *status = nil;
//    if(payResult.paymentResultStatus == UPPaymentResultStatusSuccess) {//成功
//        NSString *otherInfo = payResult.otherInfo ? payResult.otherInfo : @"";
//        NSString *successInfo = [NSString stringWithFormat:@"支付成功\n%@",otherInfo];
//        NSLog(@"%@",successInfo);
//        status = @"9000";
//    }
//    else if(payResult.paymentResultStatus == UPPaymentResultStatusCancel){//取消
//         NSLog(@"支付取消");
//        status = @"6001";
//    }
//    else if (payResult.paymentResultStatus == UPPaymentResultStatusFailure) {//失败
//        NSString *errorInfo = [NSString stringWithFormat:@"%@",payResult.errorDescription];
//        NSLog(@"失败  %@",errorInfo);
//        status = @"4000";
//    }
//    else if (payResult.paymentResultStatus == UPPaymentResultStatusUnknownCancel)  {
//        //TODO UPPAymentResultStatusUnknowCancel表示发起支付以后用户取消，导致支付状态不确认，需要查询商户后台确认真实的支付结果
//        NSString *errorInfo = [NSString stringWithFormat:@"支付过程中用户取消了，请查询后台确认订单"];
//       NSLog(@"%@",errorInfo);
//        status = @"6001";
//    }
//    [self payResult:status];
//}

-(void)initTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH-NavWithStatusBarH-YSAccountCenterBottomBarHeight) style:UITableViewStyleGrouped];
    [self.tableView setDelegate:self];
    [self.tableView setDataSource:self];
    [self.tableView setBackgroundColor:PUBLIC_BG];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

-(void)tapHead:(NSNotification *)nortif{
//   NSNumber *tag =  [nortif object];
    if(self.result.addressInfo == nil){
     [self.navigationController pushViewController:[[YSNewAddressCtrl alloc]initWithType:NewAddressSourceAccountCenterType] animated:YES];
    }else{
     [self.navigationController pushViewController:[[YSAddressCtrl alloc]initWithType:AccountCenterType] animated:YES];
    }
}

-(void)chooseAddress:(NSNotification *)nortif{
//    [self.tableView removeHeader];
    [self.emptyHeaderView removeFromSuperview];
//    [self.headerView removeFromSuperview];
    [self.tableView setTableHeaderView:self.headerView];
    
    YSAddress *address = [nortif object];
    self.result.addressInfo = address;
    [address setDetailAdres:[NSString stringWithFormat:@"%@%@",address.addressStr,address.detailAdres]];
    [self.headerView setAddress:address];
}

/**
 *  支付结果回调
 *
 *  @param aNotification 携带支付状态的通知
 */
-(void)payStatus:(NSNotification*)aNotification {
    NSString *status = [aNotification object];
    [self payResult:status];
}

-(void)payResult:(NSString *)payStatus {
    [self.navigationController popViewControllerAnimated:NO];
    [self dealToType:payStatus];
    
    //在新增订单成功以后存储这个订单号，在拿到支付状态以后做下一步处理,这个解决方法是比较鸡肋的，先这样吧
    [DefaultsHelper setObject:_addOrderResult.orderNum forKey:kOrderCode];
    [DefaultsHelper setBool:self.productType == ordinaryProductType?NO:YES forKey:kOrderType];
    NSLog(@"%@",payStatus);
}

/**
 *  判断回调那个页面
 *
 *  @param status 订单状态
 */
-(void)dealToType:(NSString *)status{
    switch (_targetType) {
        case accountCenterFinishCartType://回调购物篮
            [_delegate accountCenterFinish:accountCenterFinishCartType status:status];
            break;
            
        case accountCenterFinishOrderDetailType://回调订单详情
            [_delegate accountCenterFinish:accountCenterFinishOrderDetailType status:status];
            
        case accountCenterFinishOrderCenterType://回调订单列表
            [_delegate accountCenterFinish:accountCenterFinishOrderCenterType status:status];
            break;
            
        case accountCenterFinishProductDetailType://回调商品详情
            [_delegate accountCenterFinish:accountCenterFinishProductDetailType status:status];
            break;
        default:
            break;
    }
}

-(void)requestData{
    [YSClubDataTool getAccountCenterWithOrderCode:self.orderCode prodIds:self.selectProdIds success:^(YSAccountCenterRes *result) {
        if(result.isSucc){
           [self inflateData:result];
        }else{
            if(result.code == 2006){//过期等状态商品
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"购物篮有过期的商品，是否清除?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                [alertView show];
            }else{
                if(result.code == 1001 || result.code == 1002){
                    [Utils clearExitInfo];
                    [Utils showLoginCtrl:self];
                }
                ShowEnterTips(result.data);
            }
        }
    } failure:^(NSError *error) {
        ShowTips(kRequestFailure);
    }];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 1){
        //清除过期或缺货商品
        [YSClubDataTool expiredCart:^(BaseResponse *result) {
            if(result.isSucc){
                 ShowTips(@"清除成功");
                [self requestData];
            }else{
                 ShowEnterTips(result.data);
            }
        } failure:^(NSError *error) {
            ShowTips(kRequestFailure);
        }];
    }
}

-(void)inflateData:(YSAccountCenterRes *)result{
    _result = result;
    
    if(self.productType == ordinaryProductType){
        [self.headerView removeFromSuperview];
        [self.emptyHeaderView removeFromSuperview];
        //header
        if(result.addressInfo){
            [self.tableView setTableHeaderView:self.headerView];
            [self.headerView setAddress:result.addressInfo];
        }else{
            [self.tableView setTableHeaderView:self.emptyHeaderView];
        }
    }
    //footer
    if(result.supplierList.count){
       [self.tableView setTableFooterView:self.footerView];
       [self.bottomBar setHidden:NO];
    }else{
        [self.bottomBar setHidden:YES];
        [self.footerView removeFromSuperview];
    }
    if(self.productType == experienceProductType){
        [self.footerView.phoneView.phoneTF setText:_result.volumePhone];
    }
    
    //bottom
    [self calcWithPrice];
    
    //voucher
    if([self getCanUseCount] == 0){
        if(_result.voucherAmount > 0){//已经减去代金券的订单
            [self.bottomBar setPrice:_result.orderPrice+_result.voucherAmount amount:_result.voucherAmount];
            self.footerView.payView.iconArrow.hidden = YES;
            [self.footerView.payView.voucherNumLabel setTextColor:ThemeColor];
            [self.footerView.payView.voucherNumLabel setText:[NSString stringWithFormat:@"¥%.1f元",_result.voucherAmount]];
            [self.footerView.payView.voucherStatusLabel setText:@"已使用"];
        }else{
            [self.footerView.payView.voucherStatusLabel setText:@"未使用"];
        }
    }else{
       [self.footerView.payView.voucherNumLabel setText:[NSString stringWithFormat:@"有%d张可用",[self getCanUseCount]]];
    }
    
    //freight
    self.footerView.payView.freightConditionLabel.text = [NSString stringWithFormat:@"(满¥%ld元包邮)",_result.satisfyFreight];
    if(_result.lineFreight){
        self.footerView.payView.freightLabel.text = [NSString stringWithFormat:@"¥%ld",_result.lineFreight];
    }else{
        self.footerView.payView.freightLabel.text = @"包邮";
    }
    
    //是否显示运费
    if(self.productType == experienceProductType){
        self.footerView.payView.freightView.hidden = YES;
        [self updateContainsWithView:self.footerView.payView];
    }
    
    [_allFrames removeAllObjects];
    [_allFrames addObjectsFromArray:[self itemArrayWitFrames:result.supplierList]];
    
    [self.tableView reloadData];
}

-(void)updateContainsWithView:(UIView *)view{
    [self.footerView.payView.freightView removeConstraints:self.footerView.payView.freightView.constraints];
    
    [self.footerView.payView addConstraint:[NSLayoutConstraint
                                             constraintWithItem:self.footerView.payView.freightView
                                             attribute:NSLayoutAttributeTop
                                             relatedBy:NSLayoutRelationEqual
                                             toItem:view
                                             attribute:NSLayoutAttributeTop
                                             multiplier:1
                                             constant:0]];
    [self.footerView.payView updateConstraintsIfNeeded];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField endEditing:YES];
    return  YES;
}

-(void)selectVoucher:(UIButton *)sender{
    //选择代金券
    if(_result.voucherAmount == 0){
        YSVoucherCtrl *ctrl =  [YSVoucherCtrl initWithPrice:_result.voucherList prodPrice:_result.orderPrice isChoice:YES type:ACCOUNT_TYPE];
        [self.navigationController pushViewController:ctrl animated:YES];
    }
}

-(void)selectVoucherFinish:(NSNotification *)nortif{
    //选择代金券返回
     _voucher = [nortif object];
    [self.footerView.payView.voucherNumLabel setTextColor:ThemeColor];
    [self.footerView.payView.voucherNumLabel setText:[NSString stringWithFormat:@"¥%ld元",_voucher.amount]];
    [self.footerView.payView.voucherStatusLabel setText:@"已使用"];
    
    [self calcWithPrice];
}

/**
 *  设置商品的价格
 */
-(void)calcWithPrice{
    [self.bottomBar setPrice:_result.orderPrice amount:_voucher == nil?0:_voucher.amount];
}

/**
 *  根据模型数组 转成 frame模型数据
 *
 *  @param suppers 商家
 *
 *  @return allFrames
 */
- (NSArray *)itemArrayWitFrames:(NSArray *)suppers
{
    NSMutableArray *frames = [NSMutableArray array];
    for (int i = 0; i<suppers.count; i++) {
        NSArray *prodList = [suppers[i] prodList];
        
        NSMutableArray *childFrames = [NSMutableArray array];
        for (YSCartProduct *prod in prodList) {
            YSAccountCenterItemFrame *frame = [[YSAccountCenterItemFrame alloc] init];
            // 传递模型数据，计算所有子控件的frame
            frame.product = prod;
            [childFrames addObject:frame];
        }
        [frames addObject:childFrames];
    }
    return frames;
}

-(int)getCanUseCount{
    int canUseCount = 0;
    NSArray *voucherArray = _result.voucherList;
    for (int i = 0; i < voucherArray.count; i++) {
        YSVoucher *voucher =  voucherArray[i];
        if(![voucher isPast] && [voucher useAmount] <= _result.orderPrice){
            canUseCount++;
        }
    }
    return canUseCount;
}

#pragma  mark - UITableViewDataSource,UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  _allFrames.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_allFrames[section] count];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    YSAccountCenterBusinessHeaderView *headerView = [YSAccountCenterBusinessHeaderView headerView];
    [headerView setSupplier:_result.supplierList[section]];
    return headerView;
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return YSCartBusinessHeaderViewHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(self.productType == experienceProductType){
       YSAccountCenterExperienceBusinessFooterView *footerView =  [YSAccountCenterExperienceBusinessFooterView footerView];
        [footerView setTag:section];
        [footerView setSupplier:_result.supplierList[section]];
        return footerView;
    }else{
        YSAccountCenterBusinessFooterView *footerView = [YSAccountCenterBusinessFooterView footerView];
        [footerView.backTF setDelegate:self];
        [footerView.backTF setTag:section];
        [footerView setTag:section];
        [footerView setSupplier:_result.supplierList[section]];
        return footerView;
    }
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if(self.productType == experienceProductType){
        return YSAccountCenterExperienceBusinessFooterViewHeight;
    }else{
        return YSAccountCenterBusinessFooterViewHeight;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    YSAccountCenterCell *cell =  [YSAccountCenterCell cellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accountItemFrame = self.allFrames[indexPath.section][indexPath.row];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = [_allFrames[indexPath.section][indexPath.row] cellHeight];
    return height;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void)dealloc{
    _voucher = nil;
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
